const nodemailer = require('nodemailer');

// 云函数主逻辑
exports.main = async (event, context) => {
  const { to, subject, html } = event;

  const transporter = nodemailer.createTransport({
    host: 'smtp.qq.com',
    port: 465,
    secure: true,
    auth: {
      user: '601371494@qq.com',
      pass: 'zjqpqbqniabmbdfe'
    }
  });

  try {
    const info = await transporter.sendMail({
      from: '"民律在线" <601371494@qq.com>',
      to,
      subject,
      html
    });

    return {
      success: true,
      messageId: info.messageId
    };
  } catch (error) {
    console.error('邮件发送失败:', error);
    return {
      success: false,
      error
    };
  }
};
